package com.wanmait.movie.webController;

import com.wanmait.movie.entity.Cinema;
import com.wanmait.movie.entity.Movie;
import com.wanmait.movie.service.CinemaService;
import com.wanmait.movie.service.ScreeningService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/web/shop")
public class ShopController {
    @Resource
    private ScreeningService screeningService;
    @Resource
    private CinemaService cinemaService;
    @PostMapping("shopList")
    public AjaxResult shoppingList(@RequestBody Cinema cinema, Integer movieId){

        if (movieId == null) {
            System.out.println(this.getCinemaId(cinema));
            movieId = this.getIDEACinemaId(cinema).get(0).getId();
        }
        return AjaxResult.success(screeningService.shopList(movieId, cinema.getId()));
    }
    @PostMapping("cinemaId")
    public AjaxResult getCinemaId(@RequestBody Cinema cinema){
        return AjaxResult.success(cinemaService.getCinemaMovieList(cinema));
    }

    private List<Movie> getIDEACinemaId(@RequestBody Cinema cinema){
        return cinemaService.getCinemaMovieList(cinema);
    }
    @PostMapping("shopping")
    public AjaxResult shopping(Integer movieId){
        return AjaxResult.success(screeningService.shopping(movieId));
    }
}
